package main

import (
	"fmt"
	"html/template"
	"net/http"
)

func RunServer()  {
	http.HandleFunc("/",MyHandle)
	print("server link: http://127.0.0.1:8000")
	// 设置监听地址，和回调函数
	err := http.ListenAndServe("0.0.0.0:8000", nil)
	if err != nil {
		panic(fmt.Sprintf("服务启动失败: %+v",err.Error()))
	}
}


type Article struct {
	Title string
}

func MyHandle(w http.ResponseWriter, r *http.Request)  {
	data := r.URL.Query()

	tmpl,err := template.ParseFiles("./index.html")
	if err != nil {
		fmt.Println("create template failed :",err.Error())
		return
	}

	article := Article {
		Title: data.Get("title"),
	}

	err = tmpl.Execute(w,article)
	if err != nil {
		return
	}
}

func main() {
	RunServer()
}
